home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 7.3 KB | 253 lines | [TEXT/MPS ] |
- # **********************************************************************
- # File: Script 5 - TargetB.vu
- #
- # Purpose: To demonstrate the ability to use message passing
- #
- # Prerequistes: This script assumes that DrawShapesVU is the
- # currently active application on the target
- # and that you have turned off Key Repeat
- # in the control panel of the target computer.
- #
- # Written by: David Gaxiola
- #
- # Copyright © 1992 by Apple Computer, Inc., all rights reserved.
- #
- # **********************************************************************
-
- Libraries "StandardDialogs.vulib", "Time.vulib";
-
- # **********************************************************************
- # Calculate the absolute difference between two numbers.
- task Diff( Num1, Num2 )
- begin
- theDifference := Num1 - Num2;
- if (theDifference < 0)
- begin
- theDifference := -theDifference;
- end;
- return theDifference;
- end;
-
- # **********************************************************************
- # Wait for the the partner to give the "go."
- # Using the wait() task lessens the burden on Virtual User.
- task HoldForOther( )
- begin
- global gPartner;
-
- status := {''};
- println "Holding for {gPartner} at ", GetCurrentTime( false ), "…";
- while not (status = 'go')
- begin
- status := Receive([actor t:gPartner]);
- if not ( status = 'go' )
- wait( 2 );
- end;
- print "Proceeding at ", GetCurrentTime( false ), "…";
- end;
-
- # **********************************************************************
- # Select a given or random tool from the side palette.
- task SelectTool(toolNum := 1, randomDraw := false)
- begin
- global gWindowDim;
- global gToolColumn;
- global gToolRow;
-
- if ( randomDraw )
- toolNum := Random(2,4);
- move a:{ (gWindowDim[1] + gToolColumn),
- (gWindowDim[2] + gToolRow[toolNum]) };
- click;
- end;
-
- # **********************************************************************
- # Select a random color from the Color Picker dialog box.
- task SelectFromColorPicker( )
- begin
- global gPickerMaxScrollValue;
- global gColorPickerFixedCenter;
- global gColorPickerRadius;
-
- match [ window o:1 r:?colorPickerDim ];
- scrollValue := Random( 1, gPickerMaxScrollValue );
- scroll[ scrollbar w:[ window o:1 ]] a:{ scrollValue,
- gPickerMaxScrollValue };
- wait( 1 );
- colorPickerCenter := { (gColorPickerFixedCenter[1] +
- colorPickerDim[1]),
- (gColorPickerFixedCenter[2] +
- colorPickerDim[2]) };
- xPos := Random(0, (gColorPickerRadius * 2)) - gColorPickerRadius;
- yPos := Random(0, (gColorPickerRadius * 2)) - gColorPickerRadius;
-
- while ( (xPos * xPos) + (yPos * yPos) > gColorPickerRadius *
- gColorPickerRadius )
- begin
- xPos := Random(0, (gColorPickerRadius * 2)) - gColorPickerRadius;
- yPos := Random(0, (gColorPickerRadius * 2)) - gColorPickerRadius;
- end;
-
- x := gColorPickerCenter[1] + xPos;
- y := gColorPickerCenter[2] + yPos;
- move a:{ x, y };
- click;
- select [ button t:'OK' w:[ window o:1 ]]!;
- end;
-
- # **********************************************************************
- # Task to select one of the seven preset colors or the Color Picker
- task SelectColor(colorNum := 1, randomColor := false)
- begin
- global gColorAvail;
-
- if (gColorAvail)
- begin
- if randomColor
- begin
- colorNum := Random( 1, 9 );
- while ( colorNum = 8 )
- colorNum := Random( 1, 9 );
- end;
- select[ menuItem o:colorNum m:[ menu t:'Colors' ]];
- if colorNum = 9
- SelectFromColorPicker( );
- end;
- end;
-
- # *********************************************************************
- # Task to select one of the five possible shades
- task SelectShade(shadeNum := 1, randomShade := false)
- begin
- global gShadeMenuPos;
- global gShadeBlockSize;
- global gShadePositions;
-
- shadeLoc := gShadePositions[shadeNum];
- if ( randomShade )
- begin
- shadeNum := Random( 1, 5 );
- ShadeLoc := gShadePositions[shadeNum];
- end;
- x := gShadeMenuPos[1];
- y := gShadeMenuPos[2];
- move a:{ x, y };
- pressMouse;
- wait( 1 );
- x := gShadeBlockSize * shadeLoc[1];
- y := gShadeBlockSize * shadeLoc[2];
- move r:{ x, y };
- Wait( 1 ); # for slower targets
- releaseMouse;
- end;
-
- # **********************************************************************
- # Task to draw a rectangular shape
- task DrawRandomShapeWithTool( )
- begin
- global gWindowDim;
- global gWindowMod;
-
- range1 := ( gWindowDim[1] + gWindowMod[1] );
- range2 := ( gWindowDim[2] + gWindowMod[2] );
- range3 := ( gWindowDim[3] + gWindowMod[3] );
- range4 := ( gWindowDim[4] + gWindowMod[4] );
- xStart := Random( range1, range3 );
- yStart := Random( range2, range4 );
- xStop := Random( range1, range3 );
- yStop := Random( range2, range4 );
-
- while ( Diff( xStart, xStop ) < 40 )
- begin
- xStart := Random( range1, range3 );
- xStop := Random( range1, range3 );
- end;
-
- while ( Diff( yStart, yStop ) < 40 )
- begin
- yStart := Random( range2, range4 );
- yStop := Random( range2, range4 );
- end;
-
- move a:{ xStart,yStart };
- pressMouse;
- wait( 1 ); # for slower targer
- move a:{ xStop,yStop };
- releaseMouse;
- end;
-
- # Begin Main Body *****************************************************
- # Note: Replace "Virtual User-1" with the name of the second target.
- script Tutorial5BMain(gPartner := "Virtual User-1", maxIterations := 2, saveAsFilename := 'Tutorial 5B Example.ds')
- begin
- # Global variable definitions
- global gToolColumn := 18;
- global gToolRow := { 40, 80,120,160 };
- global gWindowMod := { 41, 21, -21, -21 };
- global gPickerMaxScrollValue := 32767;
- global gColorPickerFixedCenter := {293,137};
- global gColorPickerRadius := 100;
- global gShadeMenuPos := {125,10};
- global gShadeBlockSize := 25;
- global gShadePositions := { {0,1},{1,1},{2,1},{0,2},{1,2},{2,2} };
- global gWindowDim := { };
- global gScreenDim := { };
- global gColorAvail := false;
- global gStatus := '';
- global gPartner;
-
- # Set the actor's behavior.
- MouseSpeed( 18 );
- Patience( 4 );
-
- # Open up communications with the other target
- println "Attempting to 'open' communication with target {gPartner}.";
- while not (gStatus = 'open')
- begin
- gStatus := OpenSession([actor t:gPartner]);
- end;
-
- # Get information about the target's environment.
- match [ screen r:?gScreenDim m:true ];
- match [ menu t:?theFifthMenu o:5 ];
-
- if ( theFifthMenu = 'Colors' )
- gColorAvail := true;
- else
- gColorAvail := false;
-
- # Create a new file and set up the window to the appropriate size.
- println "Creating and setting up new DrawShapes document.";
- select [ menuItem t:'New' m:[ menu t:'File' ]];
- drag [ window t:/Untitled-≈/ o:1 ] a:{ 1, 21 };
- size [ window t:/Untitled-≈/ o:1 ] w:(gScreenDim[3] - 2) h:(gScreenDim[4] - 22);
- match [ window r:?gWindowDim o:1 ];
- if ( Diff( (gWindowDim[2] + gWindowMod[2]),
- (gWindowDim[4] + gWindowMod[4]) ) > 645 )
- begin
- temp := WindowDim[2] + gWindowMod[2] + 645 - gWindowDim[4];
- gWindowMod := Replace(temp,4,gWindowMod);
- end;
-
- # Drawshapes and communicate with the other target.
- currentIteration := 1;
- while ( currentIteration <= maxIterations )
- begin
- HoldForOther();
- SelectTool( 1, true );
- DrawRandomShapeWithTool( );
- SelectShade( 1, true );
- SelectColor( 1, true );
- currentIteration := currentIteration + 1;
- println "In iteration number {currentIteration}.";
- Send([actor t:gPartner],{'go'});
- println "Go {gPartner}!";
- end;
-
- # Save the file and end the communications session.
- println "Saving document and closing session.";
- DoSaveAs( saveAsFilename );
- CloseSession([actor t:gPartner]);
- println "Finished!";
- end; # End Main Body *****************************************************
-